package cn.xo68.metadata.mapper;


import cn.xo68.metadata.entity.MetadataColumn;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * MetadataColumn mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2020年03月12日 11:44:16
 *
 */
public interface MetadataColumnMapper {


	
	@Select("SELECT * FROM metadata_column WHERE column_id = #{columnId}")
    @Results(value = { 
    @Result(id = true, column = "column_id", property = "columnId"),
        @Result(column = "table_id", property = "tableId"),
        @Result(column = "column_name", property = "columnName"),
        @Result(column = "column_code", property = "columnCode"),
        @Result(column = "primary_key", property = "primaryKey"),
        @Result(column = "comment", property = "comment"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    MetadataColumn find(@Param("columnId") Integer columnId);
	
	@Select("SELECT * FROM metadata_column")
    @Results(value = { 
    @Result(id = true, column = "column_id", property = "columnId"),
        @Result(column = "table_id", property = "tableId"),
        @Result(column = "column_name", property = "columnName"),
        @Result(column = "column_code", property = "columnCode"),
        @Result(column = "primary_key", property = "primaryKey"),
        @Result(column = "comment", property = "comment"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    List<MetadataColumn> list();
	
	@Insert("insert into metadata_column (column_id ,table_id ,column_name ,column_code ,primary_key ,comment ,create_time ,update_time ) values (#{columnId} , #{tableId} , #{columnName} , #{columnCode} , #{primaryKey} , #{comment} , #{createTime} , #{updateTime}  )")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="columnId", before=false, resultType=Integer.class)
    @Options(useGeneratedKeys = true, keyProperty = "columnId")
    int insert(MetadataColumn metadataColumn);
	
	@Update({"update metadata_column set",
      " table_id=#{tableId}, column_name=#{columnName}, column_code=#{columnCode}, primary_key=#{primaryKey}, comment=#{comment}, create_time=#{createTime}, update_time=#{updateTime} ",
      "where column_id = #{columnId}"
    })
    int update(MetadataColumn metadataColumn);

	@Delete("delete FROM metadata_column WHERE column_id = #{columnId}")
	int delete(@Param("columnId") Integer columnId);
}